<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
	private $view = array();
	
	function __construct() {  
        parent::__construct();
        $this->load->model('common_model');
    }
	
	/**
	 * 站点主页
	*/
	public function index(){
        $this->view['menu'] = $this->common_model->all_type();//站点类别
        $this->view['list'] = $this->common_model->all_clients(0,10);//获取站点信息
        
        $this->view['operate'] = "add";
        $this->view['type'] = $this->common_model->all_type();
        
		$this->load->view('index', $this->view);
	}
    
    function main(){
        $this->load->view('main');
    }
	
	public function view_all(){
		$allclient = $this->common_model->all_clients(0, 50);
		$this->view['client'] = $allclient['result'];
		//$this->view['count'] = $allclient['count'];
		$this->view['count'] = 10;//无法加载过多数量的标注
		$this->load->view('client', $this->view);
	}
	
	//显示所有站点信息
	public function all(){
		
		$allclient = $this->common_model->all_clients();
		$this->view['client'] = $allclient['result'];
        //var_dump($allclient);die;
		$this->load->view('client/list', $this->view);
	}
	
	//添加站点信息
	public function add(){
	    $this->view['operate'] = "add";
        $this->view['type'] = $this->common_model->all_type();
		$this->load->view('client/add', $this->view);
	}
    
    function editinfo($id){
        $this->view['operate'] = "update";
        $this->view['dian'] = $this->common_model->view_client($id);
        $this->view['type'] = $this->common_model->all_type();
        $this->load->view('client/add', $this->view);
    }
    
    function saveinfo(){
        $result = false;
        $operate = $this->input->post('operate');
        $dtarr['name'] = $this->input->post('dname');
        $dtarr['address'] = $this->input->post('address');
        $dtarr['content'] = $this->input->post('content');
        $dtarr['lng'] = $this->input->post('lng');
        $dtarr['lat'] = $this->input->post('lat');
        $dtarr['typeid'] = $this->input->post('type');
        switch($operate){
            case 'add':
                $result = $this->common_model->save_client($dtarr);
            break;
            case 'update':
                $id = $this->input->post('did');
                if($id){
                    $result = $this->common_model->save_client($dtarr, array("id"=>$id));
                }
            break;
        }
        header('Location: '.BASE_URL.'/index.php/welcome/all/');
        
    }
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */